<template>
    <div class="wrap amway-detail">
        <div class="wrap-header">
            <div class="title">
                {{title}}
            </div>
            <div class="info">{{publisherName}} {{cTime}}<i class="el-icon-star-on primary ml8">{{likeCount}}</i>
            </div>
            <div class="content" v-html="content"></div>
            <div class="bottom-center pl24 pr24">
                <el-button size="mini" v-if="!isLike" @click="toLike">点 赞</el-button>
                <el-button size="mini" disabled v-else>已点赞</el-button>
            </div>
        </div>
    </div>
</template>

<script>
    // import JyEditor from "../../components/main/jy-editor.component";
    import _axios from "../../utils/axios";

    export default {
        name: "detail",
        data() {
            return {
                title: '',
                publisherName: '',
                likeCount: 0,
                cTime: '',
                content: '',
                isLike: 0,
                _id: ''
            }
        },
        // components: {JyEditor},
        methods: {
            getDetail() {
                this.$api.amway.detailAmway({
                    "shareProductionId": this.$route.query.id,
                    "userId": sessionStorage.getItem('id')
                }).then(res => {
                    this.title = res.data.title;
                    this.publisherId = res.data.publisherId;
                    this.cTime = res.data.cTime;
                    this.likeCount = res.data.likeCount;
                    this.content = res.data.content;
                    this.isLike = res.data.userShareProduction.status;
                    this._id = res.data.id;
                    this.getPublisherName();
                })

            },
            toLike() {
                this.$api.amway.amwayLike({
                    "id": this._id,
                    "shareProductionId": this.$route.query.id,
                    "status": 1,
                    "userId": sessionStorage.getItem('id')
                }).then(res => {
                    if (res.code === 200) {
                        this.$message.success('操作成功');
                        this.likeCount++;
                        this.isLike = 1;
                        // this.getDetail();
                    } else {
                        // this.$message.error(res.msg)
                        this.likeCount++;
                        this.isLike = 1;
                    }
                })
            },
            getPublisherName() {
                _axios.get('/api/api/user/getById?userId=' + this.publisherId).then(res => {
                    this.publisherName = res.data.name;
                })
                // this.$axios.get('/api/api/user/getById?userId=' + this.publisherId).then(res => {
                //     this.publisherName = res.data.name;
                // })
            }
        },
        mounted() {

            // 模拟接口返回状态，判断用户状态
            setTimeout(() => {
                this.$eventBus.emit('updateTitle', ' ')
            })

            this.getDetail();
        },
        watch: {
            'publisherId'(val) {
                if (val) {
                    this.getPublisherName();
                }
            }
        }

    }

</script>

<style rel="stylesheet/scss" lang="scss">
    .amway-detail {
        .title {
            text-align: center;
            font-size: 20px;
            font-weight: bolder;
        }

        .info {
            text-align: right;
            font-size: 14px;
            padding-right: 24px;
        }

        .content {
            padding: 24px;
        }

        .bottom {
            &-center {
                text-align: center;

            }
        }
        .primary {
            color: $text-color-primary;
        }
    }


</style>
